//
//  NewsCenterViewController.m
//  ExpressData
//
//  Created by Sun Thurein Aung on 16/02/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NewsCenterViewController.h"
#import "LatestNewsViewController.h"
#import "PromotionViewController.h"
#import "EventViewController.h"

#define latestNewsTab 0
#define promotionTab 1
#define eventTab 2

@implementation NewsCenterViewController

@synthesize tabBar, eventViewController, promotionViewController, latestNewsViewController;



// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
	switch (item.tag) {
			
			
			
		case latestNewsTab:
		{
			
			[self clearView];
			latestNewsViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
			[self.view insertSubview:latestNewsViewController.view atIndex:0];		
			
			break;
		}
		case promotionTab:
		{
			
			[self clearView];
			promotionViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
			[self.view insertSubview:promotionViewController.view atIndex:0];
			break;
		}
		case eventTab:
		{
			
			[self clearView];
			eventViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
			[self.view insertSubview:eventViewController.view atIndex:0];
			break;
		}	
		default:
			break;
	}
	
}

-(void) clearView {
	if (latestNewsViewController.view.superview) {
		[latestNewsViewController.view removeFromSuperview];
	} else if (promotionViewController.view.superview) {
		[promotionViewController.view removeFromSuperview];
	}else if (eventViewController.view.superview) {
		[eventViewController.view removeFromSuperview];
	}
} 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"News Center";
	self.tabBar.selectedItem = [self.tabBar.items objectAtIndex:0];
    [self.view insertSubview:latestNewsViewController.view atIndex:0];

	

	
}



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
